import {createRouter,createWebHistory} from 'vue-router'
import routes from './routes'
const router=createRouter({

    history:createWebHistory(import.meta.env.BASE_URL),
    routes
})

//全局前置守卫，拦截页面访问效果
router.beforeEach((to,from,next)=>{
    //如果需要登录权限，并且没有登录，则跳转到登录页
   if(to.meta.needLogin&& !sessionStorage.getItem('token')){
    next({name:'userlogin'})
   }
   else{
    next()

   }
})

export default router